package com.macro.mall.demo.controller;

import com.macro.mall.common.api.CommonResult;
import com.macro.mall.demo.dto.IndexDto;
import com.macro.mall.demo.service.EsIndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
public class EsIndexController {


    @Autowired
    private EsIndexService esIndexService;
    /**
     * 创建 索引
     */
    @PostMapping("/foundIndex")
    public void foundIndex(@Validated @RequestBody IndexDto indexDto) {
         esIndexService.foundIndex(indexDto);
    }

    /**
     * 删除索引
     */
    @DeleteMapping("/delIdnex")
    public void delIdnex(@Validated @RequestBody IndexDto indexDto) {
        esIndexService.delIdnex(indexDto);
    }

    /**
     * 修改 索引
     */
    @PostMapping("/updIndex")
    public void updIndex(@Validated @RequestBody IndexDto indexDto) {
        esIndexService.updIndex(indexDto);
    }

    /**
     * 查询 索引
     */
    @PostMapping("/selIndex")
    public void selIndex(@Validated @RequestBody IndexDto indexDto) {
        esIndexService.selIndex(indexDto);
    }

    /**
     * 判断索引 是否存在
     */
    @PostMapping("/exists")
    public CommonResult exists(@Validated @RequestBody String indexName) {
        return  esIndexService.exists(indexName);

    }

    /**
     * 上架
     */
    @GetMapping("/putaway/{ids}")
    public void putaway(@PathVariable  List<Long> ids) {
         esIndexService.putaway(ids);
    }

    /**
     * 下架
     */
    @GetMapping("/soldOut/{ids}")
    public void soldOut(@PathVariable  List<Long> ids) {
        esIndexService.soldOut(ids);
    }










}
